package com.kangzhan.utils;


import com.kangzhan.entiy.ReturnEntity;
import com.kangzhan.enums.HttpCode;
import com.kangzhan.enums.ReturnEntityEnum;

/**
 * 返回实体工具类
 *
 * @author hsh
 * @create 2018-01-24 下午 4:18
 */
public class ReturnUtil {

	/**
	 * 请求成功
	 * 
	 * @return
	 */
	public static ReturnEntity success() {
		ReturnEntity returnEntity = new ReturnEntity();
		returnEntity.setStatus(ReturnEntityEnum.SUCCESS.getStatus());
		returnEntity.setMessage(ReturnEntityEnum.SUCCESS.getMessage());
		return returnEntity;
	}

	/**
	 * 请求成功
	 * 
	 * @param datas
	 * @return
	 */
	public static ReturnEntity success(Object datas) {
		ReturnEntity returnEntity = new ReturnEntity();
		returnEntity.setStatus(ReturnEntityEnum.SUCCESS.getStatus());
		returnEntity.setMessage(ReturnEntityEnum.SUCCESS.getMessage());
		returnEntity.setDatas(datas);
		return returnEntity;
	}

	/**
	 * 服务器错误
	 * 
	 * @param datas
	 * @return
	 */
	public static ReturnEntity error(String msg) {
		ReturnEntity returnEntity = new ReturnEntity();
		returnEntity.setStatus(ReturnEntityEnum.ERROR.getStatus());
		returnEntity.setMessage(ReturnEntityEnum.ERROR.getMessage());
		returnEntity.setDatas(msg);
		return returnEntity;
	}
	public static ReturnEntity common(Object datas,String msg,Integer status) {
		ReturnEntity returnEntity = new ReturnEntity();
		returnEntity.setStatus(status);
		returnEntity.setMessage(msg);
		returnEntity.setDatas(datas);
		return returnEntity;
	}


	/**
	 * 请求失败
	 * 
	 * @param cause
	 * @return
	 */
	public static ReturnEntity fail(Integer status, String cause) {
		ReturnEntity returnEntity = new ReturnEntity();
		returnEntity.setStatus(status);
		returnEntity.setMessage(cause);
		return returnEntity;

	}

	/**
	 * 请求验证失败
	 * 
	 * @param cause
	 * @return
	 */
	public static ReturnEntity validError(HttpCode httpCode, Object cause) {
		ReturnEntity returnEntity = new ReturnEntity();
		returnEntity.setStatus(httpCode.code);
		returnEntity.setMessage(httpCode.msg);
		returnEntity.setDatas(cause);
		return returnEntity;
	}

}
